//
//  MineHeaderView.swift
//  ios_swift_demo1
//
//  Created by liutao on 2020/7/14.
//  Copyright © 2020 lt. All rights reserved.
//

import UIKit

// MARK: 我的头部背景
class MineHeaderView: UIView {
    
    private lazy var bgView:UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFill //内容缩放以填充固定的方面。部分内容可能会被
        return imageView
    }()
    
    override init(frame: CGRect) {
        super.init(frame:frame)
        setupLayout()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupLayout(){
        addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        NotificationCenter.default.addObserver(self, selector: #selector(sexTypeDidChange), name: .USexTypeDidChange, object: nil)
        sexTypeDidChange()
    }
    
    //根据男生女生判断背景
    @objc func sexTypeDidChange(){
        let sexType = UserDefaults.standard.integer(forKey: String.sexTypeKey)
        
        if sexType == 1 {
            bgView.image = UIImage(named: "mine_bg_for_boy")
            
        }else{
            bgView.image = UIImage(named: "mine_bg_for_girl")
        }
    }
    
}
